package com.alogic.validator;

import com.alogic.load.Loader;
import com.alogic.validator.loader.HotLoader;
import com.anysoft.util.PropertiesConstants;
import com.anysoft.util.Settings;

/**
 * 工厂类
 * @author yyduan
 * @since 1.6.12.11 [20181206 duanyy] <br>
 */
public class ValidatorFactory extends Loader.Manager<Validator>{

	/**
	 * 缺省的实例
	 */
	private static Loader<Validator> INSTANCE = null;
	
	/**
	 * 缺省配置文件地址
	 */
	protected static final String DEFAULT = "java:///com/alogic/validator/validator.default.xml#" + ValidatorFactory.class.getName();
			
	@Override
	protected String getDefaultClass() {
		return HotLoader.class.getName();
	}
	
	/**
	 * 获取一个缺省的Loader
	 * 
	 * 缺省Loader的配置文件通过环境变量sda.master和sda.secondary指定
	 * 
	 * @return Loader实例
	 */
	public static Loader<Validator> getDefault(){
		if (INSTANCE == null){
			synchronized (ValidatorFactory.class){
				if (INSTANCE == null){
					Settings p = Settings.get();
					String master = PropertiesConstants.getString(p, "validator.master", DEFAULT);
					String secondary = PropertiesConstants.getString(p, "validator.secondary", DEFAULT);					
					ValidatorFactory f = new ValidatorFactory();					
					INSTANCE = f.loadFrom(master, secondary);
				}
			}
		}
		return INSTANCE;
	}
}

